package com.saic.utils;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.ResultSetMetaData;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@SuppressWarnings("all")
public class MySqlUtil {

	private static  String url ;
	private static  String driver ;
	private static  String user ;
	private static  String password ;
	private static  Connection con = null;	
	private static  PreparedStatement statement = null;
	
	static {
			InputStream in = MySqlUtil.class.getClassLoader().getResourceAsStream("mysql.properties");
			Properties properties = new Properties();
			try {
				properties.load(in);
				url = properties.getProperty("url");
				user = properties.getProperty("user");
				password = properties.getProperty("password");
				Class.forName("com.mysql.jdbc.Driver");
				con = DriverManager.getConnection(url, user, password);
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
	}
	public static  String getDate (){
		String cord  ="";
		List<Map<String,String>> listMap = new ArrayList<Map<String,String>>();
	    Map<String,String> AvroInfo = new HashMap<String,String>();
		try { 
			
			String sql = "select * from Async_table";
			statement = con.prepareStatement(sql);
			ResultSet result = statement.executeQuery();
			java.sql.ResultSetMetaData rsmd = result.getMetaData();
			int colNum = rsmd.getColumnCount();
			while(result.next()){
				Map<String,String> dataMap = new HashMap<String,String>(0);
				for(int i = 1;i<=colNum;){
					dataMap.put(rsmd.getColumnName(i),result.getObject(i).toString());
					System.out.println("colume: "+rsmd.getColumnName(i)+"   value:"+result.getObject(i).toString());
					i++;
				}
			listMap.add(dataMap);
			System.out.println("cord:"+cord);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cord;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
         getDate();
	}

}
